package yyy.ab.modules.security.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import yyy.ab.common.core.ResultBean;
import yyy.ab.common.utils.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登录成功处理类
 */
@Slf4j
public class AbAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

    public AbAuthenticationSuccessHandler(String defaultTargetUrl) {
        super();
        setDefaultTargetUrl(defaultTargetUrl);
    }

    @Override
//    @SystemLog(description = "登录系统", type = LogType.LOGIN)
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        // 此处为登录成功后，后台程序额外返回操作等扩展，如下：登录成功后在前端Cookie写入
        super.onAuthenticationSuccess(request, response, authentication);
        ResponseUtil.out(response, ResultBean.success("登录成功"));
    }
}

